//链表移动
#include <stdio.h>  
#include <stdlib.h>  

typedef struct numLink  
{  
    int no;  
    struct numLink *next;  
}NODE;  
  
NODE *monenode( NODE *head, int m );  
  
void SetLink( NODE *h, int n )  
{  
    NODE *p=NULL, *q=NULL;  
    int i;  
    for( i=0; i<n; i++)  
    {  
        p = (NODE *)malloc(sizeof(NODE));  
        p->no = i+1;  
        p->next = NULL;  
        if( h->next == NULL )  
        {  
            h->next = p;  
            q = p;  
        }  
        else  
        {  
            q->next = p;  
            q = q->next;  
        }  
    }  
    return;  
}  
  
int main( )  
{  
    int n,m;  
    NODE *head=NULL, *q=NULL;  
    scanf("%d%d",&n,&m);  
    head = (NODE *)malloc(sizeof(NODE));  
    head->no = -1;  
    head->next = NULL;  
  
    SetLink( head, n );  
  
    q = monenode( head, m );  
  
    do  
    {  
        printf("%d ",q->next->no);  
        q = q->next;  
    }while( q->next != NULL );   
    printf("\n");  
    return 0;  
}  

NODE *monenode( NODE *head, int m )
{
	NODE *cur=head;
	NODE *pre;
	NODE *tem;
	NODE *final;
	
	for ( int i=0 ; i<=m ; i++ )
	{
		pre = cur;
		cur = cur->next;
	}	//此时cur指向要移动的链表的第一个，pre指向前一个

	if ( cur == NULL )
	{
		return head;
	}
	else
	{
		final = cur;
		while ( final->next != NULL )
		{
			final = final->next;
		}
		
		pre->next = NULL;
		final->next  = head->next;
		head->next = cur;
		return head;
	}
}





